//package com.tanger.common.socket;
//
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.data.redis.core.StringRedisTemplate;
//import org.springframework.stereotype.Service;
//import org.springframework.transaction.annotation.Transactional;
//
//import javax.annotation.Resource;
//import java.util.Collections;
//import java.util.Comparator;
//import java.util.List;
//import java.util.Optional;
//
//@Slf4j
//@Service
//public class IssuRedisPublisher implements EvacuteIssuService {
//
//    public static final String PUSH_CHANNEL = "SAAS-POI:ISSU-PUSH:%s:%s:%s";
//
//    @Autowired
//    private EvacuateIssuMapper mapper;
//    @Autowired
//    private EscapeRoutesMapper escapeMapper;
//    @Resource
//    private StringRedisTemplate stringRedisTemplate;
//
//    @Override
//    public List<EvacuationDistribute> findAll(String productId, String buildingId) {
//        return Optional.ofNullable(mapper.selectList(
//                        new QueryWrapper<EvacuationDistribute>()
//                                .eq("product_id",productId)
//                                .eq("building_id",buildingId)))
//                .orElseGet(Collections::emptyList);
//    }
//
//    @Override
//    public EvacuationDistribute findOne(String productId, String buildingId) {
//        return Optional.ofNullable(findAll(productId,buildingId))
//                .map(v -> v.stream()
//                        .max(Comparator.comparing(EvacuationDistribute::getCreateTime)))
//                .orElse(null)
//                .orElse(null);
//    }
//
//    @Override
//    @Transactional(rollbackFor = Exception.class)
//    public Response save(String productId, String buildingId, EvacuationDistribute issu) {
//        issu.setProductId(productId);
//        issu.setBuildingId(buildingId);
//        issu.setCreateTime(System.currentTimeMillis());
//        mapper.insert(issu);
//        publish(productId, buildingId, BeanUtils.copyProperties(issu,new IssuData()));
//        return Response.success(issu);
//    }
//
//    @Override
//    @Transactional(rollbackFor = Exception.class)
//    public Response batchDelete(List<Long> ids) {
//        mapper.deleteBatchIds(ids);
//        return Response.okMessage("OK");
//    }
//
//    @Override
//    public Response isOpen(String productId, String buildingId) {
//        int count = escapeMapper.findCount(buildingId,productId);
//        boolean f = count > 0? true:false;
//        return Response.success(f);
//    }
//
//    public void publish(String pId, String bId, IssuData data) {
//        Data d = Data.build(pId, bId, data);
//        String val = JSON.stringify(d);
//        log.info("[issu-push] publish -> {}", JSON.stringify(d));
//        stringRedisTemplate.convertAndSend(PUSH_CHANNEL, val);
//    }
//
//    public static class Data {
//        public String pId;
//        public String bId;
//        public IssuData data;
//        public static Data build(String pId, String bId, IssuData data) {
//            Data r = new Data();
//            r.pId = pId;
//            r.bId = bId;
//            r.data = data;
//            return r;
//        }
//    }
//}
